const fs = require('fs');
const path = require('path');

module.exports = function (pagePath, name) {
  const constPath = pagePath + '/const';
  if (!fs.existsSync(constPath)) {
    fs.mkdirSync(constPath);
  }
  const constName = `${name}ActionType`;

  const constFile = constPath + `/${constName}.js`;
  if (!fs.existsSync(constFile)) {
    const template = [];
    template.push(`/** redux Key */`);
    template.push(`export const key = {`);
    template.push(``);
    template.push(`};`);
    template.push(``);
    fs.writeFileSync(constFile, template.join('\n'));
  }

  const indexPath = constPath + '/index.js';
  if (!fs.existsSync(indexPath)) {
    const template = [];
    template.push(`import * as ${constName} from './${constName}';`);
    template.push(``);
    template.push(`export { `);
    template.push(` ${constName}`);
    template.push(`};`);
    template.push(``);
    fs.writeFileSync(indexPath, template.join('\n'));
  }
}
